﻿function getParams() {
    var params = {};

    var companyName = $("input[name='companyName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(companyName)) {
        params.companyName = companyName;
    }

    var orderNo = $("input[name='orderNo']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(orderNo)) {
        params.orderNo = orderNo;
    }

    params.startTime = $("input[name='startTime']").val();
    params.endTime = $("input[name='endTime']").val();

    var clientBankName = $("input[name='clientBankName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(clientBankName)) {
        params.clientBankName = clientBankName;
    }

    var clientAccountName = $("input[name='clientAccountName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(clientAccountName)) {
        params.clientAccountName = clientAccountName;
    }

    var clientOrderNo = $("input[name='clientOrderNo']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(clientOrderNo)) {
        params.clientOrderNo = clientOrderNo;
    }
    
    return params;
}

function replace_field(key) {

    var data = {
        "公司名称": "Company Name",
        "订单号": "Order#",
        "商户单号": "Merchant Order#",
        "订单时间": "Order Time",
        "收款卡号": "Receipt Card Number",
        "银行代码": "Bank Code",
        "交易类型": "Trans Type",
        "订单金额": "Amount",
        "客户银行": "Customer Bank Name",
        "客户姓名": "Customer Username",
        "客户卡号": "Customer Card#",
        "客户附言": "Postscript",
        "备注": "Remarks",
    };

    var language = FlashPay.Util.Language();

    if (!FlashPay.Util.isNullOrEmptySpance(language) && language == "en") {
        return data[key];
    } else {
        return key;
    }
}

function doSearch() {

    var columns = [[
        {
            field: 'companyName', title: replace_field('公司名称'), width: 100, align: 'left'
        },
        {

            field: 'matchOrderNo',
            title: replace_field('订单号'),
            width: 200,
            align: 'left',
            formatter: function (val, item) {

                var result = "";

                if (FlashPay.Util.isNullOrEmptySpance(val) && item.queryButtonPermission == "ReceiptMatchList005") {
                    result = '<a class="btn btn-default btn-xs" onclick="return view(this)" data-href="/view/receipt/matchsearch.html?Id={0}" data-title="{1}-查询" data-width="1200" data-height="500">查询</a>'.format(item.id, item.clientOrderNo);
                } else {
                    result = item.matchOrderNo;
                }

                if (!FlashPay.Util.isNullOrEmptySpance(item.matchOrderNo) && item.makeUpPermission == "ReceiptMatchList006") {
                    result += '<a class="btn btn-primary btn-xs m10_l" data-confirm="{0} <br>确定要<span class=red>补推送</span>吗？" data-href="/Receipt/ReceiptMatchMakeUp?id={0}&orderNo={1}">补推送</a>'.format(item.id, item.matchOrderNo);
                }

                return result;
            }
        },
        {
            field: 'clientOrderNo',
            title: replace_field('商户单号'),
            width: 200,
            align: 'left',
            formatter: function (val, item) {

                var result = val;

                result += '<button type="button" class="btn btn-default btn-xs" data-href="/view/receipt/receiptmatchedit.html?id={0}" data-title="编辑" data-width="452" data-height="600" onclick="return dialogOpen(this);"><span class="glyphicon glyphicon-edit"></span> 编辑</button>'.format(item.id);

                return result;
            }
        },
        {
            field: 'depositDate',
            title: replace_field('订单时间'),
            width: 120,
            align: 'left',
            formatter: function (val, row) {
                return val.replace("T", " ");
            }
        },

        {
            field: 'depositCardNumber',
            title: replace_field('收款卡号'),
            width: 125,
            align: 'left',
            formatter: function (val, row) {
                return val;
            }
            //bankCode
        },
        { field: 'bankCode', title: replace_field('银行代码'), width: 75, align: 'left' },
        { field: 'transtypeName', title: replace_field('交易类型'), width: 75, align: 'left' },
        {
            field: 'depositAmount',
            title: replace_field('订单金额'),
            width: 75,
            align: 'right',
            formatter: function (val, row) {
                return '<span class="bold">{0}</span>'.format(val);
            }
        },
        { field: 'clientBankName', title: replace_field('客户银行'), width: 100, align: 'left' },
        { field: 'clientAccountName', title: replace_field('客户姓名'), width: 100, align: 'left' },
        {
            field: 'clientCardNumber',
            title: replace_field('客户卡号'),
            width: 125,
            align: 'left',
            formatter: function (val, row) {
                return val;
            }
        },
        { field: 'postScript', title: replace_field('客户附言'), width: 150, align: 'left' },
        { field: 'depositRemark', title: replace_field('备注'), width: 200, align: 'left' }
    ]];

    $("#easyui-treegrid").datagrid({
        fit: false,
        loadMsg: '数据加载中，请稍后……',
        url: '/DepositMatchRecord/GetDepositMatchRecord',
        queryParams: getParams(),
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        pageSize: pageSize,
        pageList: [50, 200, 500, 1000],
        height: $(window).height() - 70,
        idField: 'orderNo',
        onLoadSuccess: function () {
            pageSize = $('#easyui-treegrid').datagrid('options').pageSize;
        },
        frozenColumns: [[]],
        columns: columns
    });
}